package logic

import (
	"context"
	"order_srv/order"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderCreateLogic {
	return &OrderCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderCreateLogic) OrderCreate(req *types.OrderCreaterequest) (resp *types.Response, err error) {
	create, err := l.svcCtx.Orderrpc.OrderCreate(l.ctx, &order.OrderCreateRequest{
		UserId:   int64(req.UserId),
		GoodsId:  int64(req.GoodsId),
		OrderNum: int64(req.OrderNum),
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Code:    200,
		Message: "创建订单成功",
		Data:    create,
	}, nil
}
